home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / awe2-0_1.lha / awe2-0.1 / Src / RCS / Thread.cc,v < prev    next >
Text File  |  1989-10-24  |  5KB  |  230 lines

  1. head     3.3;
  2. branch   ;
  3. access   ;
  4. symbols  ;
  5. locks    grunwald:3.3; strict;
  6. comment  @@;
  7.  
  8.  
  9. 3.3
  10. date     89.10.24.13.08.37;  author grunwald;  state Exp;
  11. branches ;
  12. next     3.2;
  13.  
  14. 3.2
  15. date     89.02.20.15.37.47;  author grunwald;  state Exp;
  16. branches ;
  17. next     3.1;
  18.  
  19. 3.1
  20. date     88.12.20.13.49.21;  author grunwald;  state Exp;
  21. branches ;
  22. next     1.2;
  23.  
  24. 1.2
  25. date     88.10.30.13.04.41;  author grunwald;  state Exp;
  26. branches ;
  27. next     1.1;
  28.  
  29. 1.1
  30. date     88.09.18.16.42.30;  author grunwald;  state Exp;
  31. branches ;
  32. next     ;
  33.  
  34.  
  35. desc
  36. @@
  37.  
  38.  
  39. 3.3
  40. log
  41. @*** empty log message ***
  42. @
  43. text
  44. @// This may look like C code, but it is really -*- C++ -*-
  45. // 
  46. // Copyright (C) 1988 University of Illinois, Urbana, Illinois
  47. //
  48. // written by Dirk Grunwald (grunwald@@cs.uiuc.edu)
  49. //
  50. #include "CpuMultiplexor.h"
  51. #include "CpuMultiplexorP.h"
  52. #include "Thread.h"
  53. #include "ThreadContainer.h"
  54. #include "assert.h"
  55.  
  56. const void * UNINITIALIZED = 0;
  57.  
  58. Thread::Thread(char* name, unsigned stacksize,
  59.            ThreadPriority priority, bool xdebug, int checkStack)
  60.     : (xdebug), pContext(checkStack, stacksize)
  61. {
  62.     threadName = name;
  63.     threadPriority = priority;
  64.     threadState = RUNNABLE;
  65.     cpuAffinity = -1;
  66.  
  67.     pContext.buildReturnFrame(this, voidFuncP(&Thread::startOff));
  68.  
  69.     if (debugFlag) {
  70.     cerr << "[create Thread " << name << " at " << hex(long(this)) << "\n";
  71.     }
  72.     
  73. }
  74.  
  75. Thread::~Thread()
  76. {
  77.     makeTerminated();
  78.     //
  79.     //    The destructor for HardwareContext doesn't free the stack space.
  80.     //  If a thread other than the this thread is calling the destructor,
  81.     //  we need to reclaim that stack space now.
  82.     //
  83.     //  If the current thread is calling the destructor, it must do so
  84.     //  by returning from main & the via the delete statement in startOff.
  85.     //  In that case, we delete the stack in startOff.
  86.     //
  87.     //  It is considered an error for this thread to delete itself in any
  88.     //  other way (i.e. you can do it, but don't complain about what happens).
  89.     //
  90.     if ( this != CurrentThread() ) {
  91.     void **p = pContext.mallocAt();
  92.     delete p;
  93.     }
  94. }
  95.  
  96. void Thread::main()
  97. {
  98.     assert2(FALSE, "[Thread] Subclass of thread forgot to specialize main()");
  99. }
  100.  
  101. void
  102. Thread::startOff()
  103. {
  104.     main();
  105.     void **p = pContext.mallocAt();
  106.     delete this;
  107.     ThisCpu -> threadTerminateException( p );
  108.     assert2(FALSE,"[Thread] Thread exits main");
  109. }
  110.  
  111. void Thread::makeTerminated()
  112. {
  113.     //
  114.     //    this doesn't do anything yet. It's not clear it's needed either,
  115.     //  since most termination-oriented things could happen in the
  116.     //  destructor.
  117.     //
  118. }
  119.  
  120. void Thread::classPrintOn(ostream& strm)
  121. {
  122.     strm << "[Thread:"
  123.      << " " << threadName
  124.          << "  pri: " << int(threadPriority)
  125.          << "  state: ";
  126.     switch (threadState) {
  127.     case SUSPENDED:
  128.     strm << "SUSPENDED";
  129.     break;
  130.     case RUNNING:
  131.     strm << "RUNNING";
  132.     break;
  133.     case RUNNABLE:
  134.     strm << "RUNNABLE";
  135.     break;
  136.     case TERMINATED:
  137.     strm << "TERMINATED";
  138.     break;
  139.  
  140.     case ZOMBIED:
  141.     default: strm << "INVALID";
  142.     break;
  143.     }
  144.     strm << "]\n";
  145.     strm << pContext << "\n";;
  146. }
  147. @
  148.  
  149.  
  150. 3.2
  151. log
  152. @Start using Gnu library heaps for schedulers
  153. @
  154. text
  155. @d8 1
  156. a13 1
  157. const double NullTime = -1;
  158. d16 1
  159. a16 1
  160.            ThreadPriority priority, int xdebug, int checkStack)
  161. @
  162.  
  163.  
  164. 3.1
  165. log
  166. @Steay version
  167. @
  168. text
  169. @@
  170.  
  171.  
  172. 1.2
  173. log
  174. @*** empty log message ***
  175. @
  176. text
  177. @d22 1
  178. @
  179.  
  180.  
  181. 1.1
  182. log
  183. @Initial revision
  184. @
  185. text
  186. @d1 7
  187. a7 1
  188. #include "HardwareCpu.h"
  189. d15 3
  190. a17 3
  191. Thread::Thread(const char* name, unsigned stacksize,
  192.            ThreadPriority priority, int xdebug)
  193.     : (xdebug), pContext(1, stacksize)
  194. a30 4
  195. //
  196. //    You better hope to god that *this* isn't the current context
  197. //    of any executing thread.
  198. //
  199. d33 1
  200. d35 3
  201. a37 4
  202.     // If delete is called by a thread
  203.     // then
  204.     //  the raise at this point will switch us to the Hardware context,
  205.     //  which then calls delete.
  206. d39 3
  207. a41 3
  208.     // else if delete is called by the Hardware context
  209.     //   then the raise simply ``falls through'', since we'll be
  210.     //   stopping & then restarting the hardware context (right here).
  211. d43 2
  212. a44 5
  213.     // The only problem is if someone *else* calls the delete, we need
  214.     // to just let them delete it & return. If we raise the exception,
  215.     // they'll eventually restart here after the Hardware context
  216.     // has deleted the state, and they'll delete it again, causing
  217.     // much mahem.
  218. d46 3
  219. a48 2
  220.     if ( this == CurrentThread() ) {
  221.     ThisCpu -> threadTerminateException( this );
  222. a49 1
  223.     makeTerminated();
  224. d61 3
  225. a63 1
  226.     ThisCpu -> threadTerminateException( this );
  227. d69 5
  228. d95 2
  229. @
  230.